WDV221 Intro Javascript

Javascript Date Object - Homework 8


Please complete the following exercises on this page. When complete post the page to your WDV221 folder on the server. Make a link in your WDV221 Intro Javascript page for this assignment. Contact your instructor and demonstrate that you have completed the assignment.

Using Blackboard complete the In Class Exercise Assignment. Download your Homework project and being working on it with your remaining time.

When you complete this exercise you will have a selection of very useful scripts that you can use in any of your future scripts. I would suggest starting a library of scripts in an external javascript file. You can then use these in multiple pages.

For each exercise use a comment line to put the Exercise number within the script. Also place a short description of what the script is doing.


1. Create a function called getDayOfWeek( ). This function will accept an integer(0-6) as a parameter. Based upon the integer it will return the name of the day of the week. Example: 1 will return 'Monday'.

2. Create a function called getMonth( ). This function will accept a Date object as a parameter. It will return the appropriate numeric month code for the date object. Example: March will return 3 instead of 2.

3. Create a function called getFullMonth( ). This function will accept an integer(0-11) as a parameter. It will return the full name of the month based upon the value of the parameter. Example: 6 will return 'July'.

4. Create a function called getShortMonth( ). This function will accept an integer(0-11) as a parameter. It will return the short name(first three characters) of the month based upon the value of the parameter. Example: 6 will return 'Jul'.

5. Create a function called getYear( ). This function will accept a Date object as a parameter. It will return the four digit (YYYY) year of the data object.

6. Create a function called lastUpdate( ). This function will access the .lastModified date of the current page. It will return a string formatted like "Last Updated: mm/dd/yyyy". Hint: Create a new date object using the .lastModified value as input.

Note: The following functions should call the previous functions as needed. Example: When you need the month use the getMonth( ) function to get the month for mm.

7. Create a function called dateUS( ). This function will accept a Date object as a parameter. It will return a string in the following format 'mm/dd/yyyy' based upon the value of the parameter.

8. Create a function called dateEU( ). This function will accept a Date object as a parameter. It will return a string in the following format 'dd/mm/yyyy' based upon the value of the parameter.

9. Create a function called fullDate( ). The function will accept a Date object as a parameter. It will return a string formatted like 'Wednesday March 13, 2013'.

Use the functions created above to display the appropriate values for the following examples.

10. Create a Date object called today. Use a runtime script and document.write( ) to output the requested results.

The current day is:

The current day of the week is:

The current month is:

The current short month is:

The current year is:

Format today's date into mm/dd/yyyy and display:

Format today's date into dd/mm/yyyy and display:

Ten days from today will be: (full date)

Last Updated:

 

Extra Credit:

ex1. Create a function called getZeroMonth( ). This function will accept a date object as a parameter. It will return the expected numeric month. It will be formatted so that any single digit month has a preceding zero. For example the month of March should be returned as '03'.

ex2. Create a function called getZeroDate( ). This function will accept a date object as a parameter. It will return the expected numeric date. It will be formatted so that any single digit date has a preceding zero. For example the date 7 should be returned as '07'.